package com.haonan.service.Impl;

import com.haonan.mapper.EmpMapper;
import com.haonan.mapper.StudentMapper;
import com.haonan.pojo.vo.JobVO;
import com.haonan.pojo.vo.StudentClazzVO;
import com.haonan.pojo.vo.StudentCountVO;
import com.haonan.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private EmpMapper empMapper;

    /**
     * 统计员工性别
     * @return
     */
    public List<Map<String, Object>> getEmpGenderData() {
        List<Map<String, Object>> list = empMapper.findGender();
        return list;
    }

    /**
     * 统计各个职位的员工数量
     * @return
     */
    public JobVO getEmpJobData() {
        //1.调用mapper接口,获取统计数据
        List<Map<String,Object>>list=empMapper.countEmpJobDate();//map: 职位名称，数量
        //2.组装数据，并返回
        List<String> jobList=list.stream().map(m->m.get("job").toString()).toList();
        List<Object> dataList=list.stream().map(m->m.get("data")).toList();
        return new JobVO(jobList,dataList);
    }

    /**
     * 统计学历及其数量
     * @return
     */
    public List<StudentCountVO> getStudentDegreeData() {
        return studentMapper.getStudentDegreeData();
    }

    /**
     * 统计班级及其数量
     * @return
     */
    public StudentClazzVO getStudentCountData() {
        List<Map<String,Object>> list=studentMapper.getStudentCountData();
        List<String> clazzList=list.stream().map(m->m.get("clazzName").toString()).toList();
        List<Object> dataList=list.stream().map(m->m.get("data")).toList();
        return new StudentClazzVO(clazzList,dataList);
    }
}
